

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Linq;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
using Telerik.OpenAccess;
using AcademyDocs.Web;

#pragma warning disable 1591

namespace AcademyDocs.Web	
{    
    [EnableClientAccess()]
    public partial class AcademyDocsDomainService : OpenAccessDomainService< EntitiesModel >
	{
		public AcademyDocsDomainService() : base()
		{
            
		}

        public IQueryable<Folder> GetUserRootFolders(string username)
        {
            Aspnet_User userFound =  this.DataContext.Aspnet_Users.SingleOrDefault(user => user.UserName == username);

            if (userFound.Folder == null)
            {
                userFound.Folder = new Folder()
                {
                    Name = "DefaultRootFolder"
                };
                this.DataContext.SaveChanges();
            }
            

            return DataContext.Folders.Where(f=> f.ParentFolderId==userFound.RootFolderId);
        }

        public Folder GetUserRootFolderId(string username)
        {
            Aspnet_User userFound = this.DataContext.Aspnet_Users.SingleOrDefault(user => user.UserName == username);

            if (userFound.RootFolderId == null)
            {
                userFound.Folder = new Folder()
                {
                    Name = "DefaultRootFolder"
                };
                this.DataContext.SaveChanges();
            }

            return userFound.Folder;
        }

        public Folder GetParentFolderId(int? id)
        {
            Folder folder = this.DataContext.Folders.FirstOrDefault(f=>f.FolderId==id);

            return folder;
        }


        public IQueryable<Folder> GetFoldersByParentFolderId(int parentFolderId)
        {
            return this.DataContext.Folders.Where(folder => folder.ParentFolderId == parentFolderId);
        }

		public IQueryable<Aspnet_User> GetAspnet_Users()
		{ 
			return this.DataContext.Aspnet_Users;
		}       
		public void DeleteAspnet_Users(Aspnet_User aspnet_User)
		{
			// This is a callback method. The actual Delete is performed internally.
		}

		public void UpdateAspnet_Users(Aspnet_User aspnet_User)
		{
			// This is a callback method. The actual Update is performed internally.
		}

		public void InsertAspnet_Users(Aspnet_User aspnet_User)
		{
			// This is a callback method. The actual Insert is performed internally.
		} 
		public IQueryable<File> GetFiles()
		{ 
			return this.DataContext.Files;
		}       
		public void DeleteFiles(File file)
		{
			// This is a callback method. The actual Delete is performed internally.
		}

		public void UpdateFiles(File file)
		{
			// This is a callback method. The actual Update is performed internally.
		}

		public void InsertFiles(File file)
		{
			// This is a callback method. The actual Insert is performed internally.
		} 
		public IQueryable<Folder> GetFolders()
		{ 
			return this.DataContext.Folders;
		}       
		public void DeleteFolders(Folder folder)
		{
			// This is a callback method. The actual Delete is performed internally.
		}

		public void UpdateFolders(Folder folder)
		{
			// This is a callback method. The actual Update is performed internally.
		}

		public void InsertFolders(Folder folder)
		{
			// This is a callback method. The actual Insert is performed internally.
		} 
	}
}

#pragma warning restore 1591
